package com.hafu.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import static sun.plugin.javascript.navig.JSType.URL;

public class DbUtil {
    public static final String URL = "jdbc:mysql://localhost:3306/db_jxcms1?useUnicode=true&characterEncoding=utf8";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "123456";
    public static Connection connection = null;

    public static Connection getConn(){
        try {
            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
            System.out.println("数据库连接成功");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return connection;
    }

    public static void closeConn(){
        try{
            if (connection != null){
                connection.close();
            }
        }catch (SQLException throwables){
            throwables.printStackTrace();
        }
    }
public static void main(String[] args) {
        System.out.println(DbUtil.getConn());
}
    }


